<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <div v-if="crud.props.searchToggle">
        <!-- 搜索 -->
        <label class="el-form-item-label">班组编码</label>
        <el-input v-model="query.teamGroupCode" clearable placeholder="班组编码" style="width: 185px;" class="filter-item"
                  @keyup.enter.native="crud.toQuery"/>
        <label class="el-form-item-label">班组名称</label>
        <el-input v-model="query.teamGroupName" clearable placeholder="班组名称" style="width: 185px;" class="filter-item"
                  @keyup.enter.native="crud.toQuery"/>
        <label class="el-form-item-label">是否禁用</label>
        <el-input v-model="query.isDisable" clearable placeholder="是否禁用" style="width: 185px;" class="filter-item"
                  @keyup.enter.native="crud.toQuery"/>
        <rrOperation :crud="crud"/>
      </div>
      <!--如果想在工具栏加入更多按钮，可以使用插槽方式， slot = 'left' or 'right'-->
      <crudOperation :permission="permission"/>
      <!--表单组件-->
      <el-dialog :close-on-click-modal="false" :before-close="crud.cancelCU" :visible.sync="crud.status.cu > 0"
                 :title="crud.status.title" width="500px">
        <el-form ref="form" :model="form" :rules="rules" size="small" label-width="80px">
          <el-form-item label="班组编码" prop="teamGroupCode">
            <el-input v-model="form.teamGroupCode" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="班组名称" prop="teamGroupName">
            <el-input v-model="form.teamGroupName" style="width: 370px;"/>
          </el-form-item>
          <el-form-item label="是否禁用" prop="isDisable">
            <el-radio v-model="form.isDisable" v-for="item in dict.whether" :key="item.id" :label="item.value">{{
              item.label }}
            </el-radio>
          </el-form-item>
          <el-form-item label="备注说明">
            <el-input v-model="form.remark" style="width: 370px;"/>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="text" @click="crud.cancelCU">取消</el-button>
          <el-button :loading="crud.status.cu === 2" type="primary" @click="crud.submitCU">确认</el-button>
        </div>
      </el-dialog>
      <!--班组详情-->
      <el-dialog
        width="70%"
        title="班组详情"
        :visible.sync="innerVisible"
        append-to-body>
        <el-row v-if="this.data">
          <!--班组信息-->
          <el-col :span="24">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>班组信息</span>
                <el-button style="float: right; padding: 3px 0" type="text" @click="crud.toEdit(crud.data[0])">修改班组</el-button>
              </div>
              <el-descriptions title="班组信息">
                <el-descriptions-item label="班组名称">{{this.data.teamGroupName}}</el-descriptions-item>
                <el-descriptions-item label="班组编码">{{this.data.teamGroupCode}}</el-descriptions-item>
                <el-descriptions-item label="是否禁用">
                  <el-tag size="small">{{this.data.isDisable == "0" ? "否":"是"}}</el-tag>
                </el-descriptions-item>
                <el-descriptions-item label="备注">{{this.data.remark}}</el-descriptions-item>
              </el-descriptions>
            </el-card>
          </el-col>
          <!--班组人员信息-->
          <el-col :span="24">
            <el-card class="box-card">
              <div slot="header" class="clearfix">
                <span>人员信息</span>
              </div>
              <teamEmployee :id="this.data.id"></teamEmployee>
            </el-card>
          </el-col>
        </el-row>
      </el-dialog>
      <!--表格渲染-->
      <el-empty
        v-show="!crud.data || crud.data.length == 0"
        description="暂无数据"
      ></el-empty>
      <!--渲染列表-->
      <el-row
        :gutter="20"
        v-show="crud.data && crud.data.length > 0"
        v-loading="crud.loading"
      >
        <el-col :span="6" v-for="(item, index) in crud.data" :key="item.id">
          <div class="grid-content bg-purple">
            <el-card class="box-card">
              <div class="top">
                <img src="@/assets/images/班组维护.png" class="img" />
                <div class="content">
                  <div class="titleName">{{ item.teamGroupName }}</div>
                  <div class="subTitle">班组编号: {{ item.teamGroupCode }}</div>
                  <div class="subTitle">
                    是否禁用:
                    <el-tag size="small" type="danger" v-if="item.isDisable === '1'">{{
                      dict.label.whether[item.isDisable]
                      }}</el-tag>
                    <el-tag size="small" v-if="item.isDisable === '0'">{{
                      dict.label.whether[item.isDisable]
                      }}</el-tag>
                  </div>
                </div>
              </div>
              <div class="bottom">
                <el-button-group style="width: 70px;white-space:nowrap; ">
                  <i
                    class="el-icon-edit button"
                    style="cursor: pointer"
                    @click="particulars(item)"
                  ></i>
                  <i
                    class="el-icon-delete button"
                    style="cursor: pointer"
                    @click="toDelete(item)"
                  ></i>
                </el-button-group>
                <div class="time">创建时间: {{ item.createTime }}</div>
              </div>
            </el-card>
          </div>
        </el-col>
      </el-row>
      <!--分页组件-->
      <pagination/>
    </div>
  </div>
</template>

<script>
  import crudFactoryTeamGroup from '@/api/factory/factoryTeamGroup'
  import CRUD, {presenter, header, form, crud} from '@crud/crud'
  import rrOperation from '@crud/RR.operation'
  import crudOperation from '@crud/CRUD.operation'
  import udOperation from '@crud/UD.operation'
  import pagination from '@crud/Pagination'
  import teamEmployee from '../team_employee/index'

  const defaultForm = {
    id: null,
    teamGroupCode: null,
    teamGroupName: null,
    isDisable: "0",
    remark: null,
    createBy: null,
    createTime: null,
    updateBy: null,
    updateTime: null
  }
  export default {
    name: 'FactoryTeamGroup',
    components: {pagination, crudOperation, rrOperation, udOperation, teamEmployee},
    mixins: [presenter(), header(), form(defaultForm), crud()],
    dicts: ['whether'],
    cruds() {
      return CRUD({
        title: '班组管理',
        url: 'api/factoryTeamGroup',
        idField: 'id',
        sort: 'id,desc',
        crudMethod: {...crudFactoryTeamGroup}
      })
    },
    data() {
      return {
        innerVisible:false,
        data:null,
        permission: {
          add: ['admin', 'factoryTeamGroup:add'],
          edit: ['admin', 'factoryTeamGroup:edit'],
          del: ['admin', 'factoryTeamGroup:del']
        },
        rules: {
          teamGroupCode: [
            {required: true, message: '班组编码不能为空', trigger: 'blur'}
          ],
          teamGroupName: [
            {required: true, message: '班组名称不能为空', trigger: 'blur'}
          ],
          isDisable: [
            {required: true, message: '是否禁用不能为空', trigger: 'blur'}
          ]
        },
        queryTypeOptions: [
          {key: 'teamGroupCode', display_name: '班组编码'},
          {key: 'teamGroupName', display_name: '班组名称'},
          {key: 'isDisable', display_name: '是否禁用'}
        ]
      }
    },
    methods: {
      // 钩子：在获取表格数据之前执行，false 则代表不获取数据
      [CRUD.HOOK.beforeRefresh]() {
        return true
      },
      //详情
      particulars(data){
        this.data = data
        this.innerVisible=true
      },
      // 确认删除
      toDelete(data) {
        this.$confirm("确定删除该班组?", "提示", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        })
          .then(() => {
            this.crud.doDelete(data);
          })
          .catch(() => {});
      },
    }
  }
</script>

<style scoped>
  .header-bottom {
    padding-bottom: 10px;
  }
  .el-card {
    margin-bottom: 15px;
  }
  .top {
    width: 100%;
    margin-bottom: 12px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    justify-content: flex-start;
    align-items: flex-start;
    font-family: PingFangSC-Regular;
  }
  .img {
    width: 64px;
    margin-right: 15px;
  }
  .content {
    overflow: hidden;
    flex: 1 1;
  }
  .titleName {
    font-size: 14px;
    color: #333;
    line-height: 22px;
    font-weight: 700;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .subTitle {
    font-size: 12px;
    color: #555;
    line-height: 20px;
    margin-bottom: 8px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .descWrapper {
    font-size: 12px;
    color: #555;
    line-height: 20px;
    margin-bottom: 8px;
    display: flex;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .descContent {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .bottom {
    display: flex;
    justify-content: space-between;
    align-items: center;
    justify-content: flex-start;
  }
  .bottom .time {
    font-size: 13px;
    margin-left: 8px;
    color: #999;
    overflow:hidden;
    text-overflow:ellipsis;
    white-space:nowrap;
  }
  .bottom .button {
    font-size: 18px;
    padding: 0 7px;
  }
  .bottom .button:hover {
    color: #409eff;
  }
</style>
